package hl.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;

import hl.pageModel.CourseDetail;
import hl.pageModel.DataGrid;
import hl.pageModel.Json;
import hl.service.CourseDetailService;

@Namespace("/")
@Action(value = "courseDetailAction")
public class CourseDetailAction extends BaseAction implements ModelDriven<CourseDetail> {

	CourseDetail courseDetail = new CourseDetail();

	private CourseDetailService courseDetailService;

	@Override
	public CourseDetail getModel() {
		return courseDetail;
	}

	public CourseDetailService getCourseDetailService() {
		return courseDetailService;
	}

	@Autowired
	public void setCourseDetailService(CourseDetailService courseDetailService) {
		this.courseDetailService = courseDetailService;
	}

	public void add() {
		Json j = new Json();
		try {
			courseDetailService.save(courseDetail);
			j.setSuccess(true);
			j.setMsg("保存成功");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void getDatagrid() {
		DataGrid d = courseDetailService.getDatagrid(courseDetail);
		super.writeJson(d);
	}

	public void edit() {
		Json j = new Json();
		try {
			courseDetailService.edit(courseDetail);
			j.setSuccess(true);
			j.setMsg("修改成功！");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void remove() {
		Json j = new Json();
		try {
			courseDetailService.remove(courseDetail);
			j.setSuccess(true);
			j.setMsg("删除成功！");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}
	
	public void getComboBox() {
		super.writeJson(courseDetailService.getComboBox(courseDetail));
	}
	
	public void getCharts() {
		super.writeJson(courseDetailService.getCharts());
	}
}
